package xcmg.device.service.vehicle;

import com.github.pagehelper.PageInfo;
import yb.ecp.fast.infra.util.PageHelperPlus;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.dao.entity.warehouse.WarehouseDeliveryDO;
import xcmg.device.dao.entity.warehouse.WarehouseDeliveryDetailDO;
import xcmg.device.dao.mapper.warehouse.WarehouseDeliveryDetailMapper;
import xcmg.device.dao.mapper.warehouse.WarehouseDeliveryMapper;
import xcmg.device.service.vo.warehouse.WarehouseDeliveryDetailVO;
import xcmg.device.service.vo.warehouse.WarehouseDeliveryVO;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.ArrayList;
import java.util.List;

@Service
public class VehicleService {

    @Autowired
    private WarehouseDeliveryDetailMapper warehouseDeliveryDetailMapper;

    @Autowired
    private WarehouseDeliveryMapper warehouseDeliveryMapper;

    public PageCommonVO list(SearchCommonVO<WarehouseDeliveryVO> condition) {
        PageCommonVO<WarehouseDeliveryVO> pageCommonVO = new PageCommonVO();
        PageHelperPlus.orderBy("create_date asc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<WarehouseDeliveryDO> doList = warehouseDeliveryMapper.listForVehicle(condition.getFilters());
        List<WarehouseDeliveryVO> voList = new ArrayList<>();
        for (WarehouseDeliveryDO entity : doList) {
            WarehouseDeliveryVO model = new WarehouseDeliveryVO();
            BeanUtils.copyProperties(entity, model);
            voList.add(model);
        }
        pageCommonVO.setPageInfo(new PageInfo(doList));
        pageCommonVO.setPageInfoList(voList);
        return pageCommonVO;
    }

    public PageCommonVO listDetial(SearchCommonVO<WarehouseDeliveryVO> condition) {
        PageCommonVO<WarehouseDeliveryDetailVO> pageCommonVO = new PageCommonVO();
        PageHelperPlus.orderBy("create_date asc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<WarehouseDeliveryDetailDO> doList = warehouseDeliveryDetailMapper.listForVehicle(condition.getFilters());
        List<WarehouseDeliveryDetailVO> voList = new ArrayList<>();
        for (WarehouseDeliveryDetailDO entity : doList) {
            WarehouseDeliveryDetailVO model = new WarehouseDeliveryDetailVO();
            BeanUtils.copyProperties(entity, model);
            voList.add(model);
        }
        pageCommonVO.setPageInfo(new PageInfo(doList));
        pageCommonVO.setPageInfoList(voList);
        return pageCommonVO;
    }

}
